home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / DEMO_APP / GRID.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  2.6 KB  |  83 lines

  1. package sub_arctic.demo_apps;
  2.  
  3. import sub_arctic.lib.*;
  4. import sub_arctic.output.*;
  5. import sub_arctic.input.*;
  6. import sub_arctic.constraints.std_function; 
  7.  
  8. /* grid.java
  9.  * This is a very simple grid container.  All elements must be filled in, and
  10.  * they must be filled in order starting from 0,0.
  11.  *
  12.  * 9/24/96 Colleen Kehoe
  13.  *
  14.  */
  15.  
  16. public class grid extends shrink_wrap_container {
  17.   
  18.   interactor[][] elements;
  19.   int rows;
  20.   int columns;
  21.  
  22.   public grid(int r, int c) {
  23.     super(0,0,2,true);
  24.     rows = r;
  25.     columns = c;
  26.     elements = new interactor[rows][columns];
  27.   }
  28.  
  29.   public interactor element_at(int i, int j) {
  30.     return elements[i][j];
  31.   }
  32.  
  33.   public void set_element_at(int i, int j, interactor n) {
  34.     elements[i][j] = n;
  35.     
  36.  
  37.     // If we're not in the first column, set our x to be the maximum of the right
  38.     // edge (X2) of the element to our left and the left edge (X1) of the element
  39.     // above us.  Similarly for our y value if we're not in the first row.
  40.     if (i != 0 && j != 0) {
  41.       elements[i][j].set_x_constraint(std_function.max(OTHER.OBJ(elements[i][j-1]).X2(),OTHER.OBJ(elements[i-1][j]).X1(),0));
  42.       elements[i][j].set_y_constraint(std_function.max(OTHER.OBJ(elements[i-1][j]).Y2(),OTHER.OBJ(elements[i][j-1]).Y1(),0));
  43.  
  44.     } else {
  45.  
  46.       // If we are in the first column, set our x to our parent's left edge.
  47.       // Otherwise, set it to the right edge of the element to our left.
  48.       if (j == 0) {
  49.     elements[i][j].set_x_constraint(std_function.eq(PARENT.X1()));
  50.       } else {
  51.     elements[i][j].set_x_constraint(std_function.eq(OTHER.OBJ(elements[i][j-1]).X2()));
  52.       }
  53.  
  54.       // If we are in the first row, set our y to our parent's top edge.
  55.       // Otherwise, set it to the bottom edge of the element above us.
  56.       if (i == 0) {
  57.     elements[i][j].set_y_constraint(std_function.eq(PARENT.Y1()));
  58.       } else {
  59.     elements[i][j].set_y_constraint(std_function.eq(OTHER.OBJ(elements[i-1][j]).Y2()));
  60.     
  61.       }
  62.     }
  63.     add_child(elements[i][j]);
  64.   }
  65.  
  66. }
  67. /*=========================== COPYRIGHT NOTICE ===========================
  68.  
  69. This file is part of the subArctic user interface toolkit.
  70.  
  71. Copyright (c) 1996 Scott Hudson and Ian Smith
  72. All rights reserved.
  73.  
  74. The subArctic system is freely available for most uses under the terms
  75. and conditions described in 
  76.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  77. and appearing in full in the lib/interactor.java source file.
  78.  
  79. The current release and additional information about this software can be 
  80. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  81.  
  82. ========================================================================*/
  83.